package cn.humaohua.study.yanmo_design_pattern.ch04.v3;

import cn.humaohua.study.yanmo_design_pattern.ch04.v1.LogFileOperate;
import cn.humaohua.study.yanmo_design_pattern.ch04.v1.LogFileOperateApi;
import cn.humaohua.study.yanmo_design_pattern.ch04.v1.LogModel;
import cn.humaohua.study.yanmo_design_pattern.ch04.v2.LogDbOperate;
import cn.humaohua.study.yanmo_design_pattern.ch04.v2.LogDbOperateApi;

import java.util.List;

public class Main {
    public static void main(String[] args) {
        // 日志文件操作
        log_file_test();
        // 日志数据库操作
        log_db_test();
        // 日志操作，通过适配器，将文件保存到文件中
        log_adapter_test();
    }

    private static void log_file_test() {
        System.out.println("test file...");
        LogFileOperateApi logFileOperate;
        logFileOperate = new LogFileOperate(null);
        List<LogModel> list = logFileOperate.readLogFile();
        System.out.println(list);
    }

    private static void log_db_test() {
        System.out.println("test db...");
        LogDbOperateApi logDbOperate = new LogDbOperate();
        logDbOperate.createLog(null);
        logDbOperate.getAllLog();
    }

    private static void log_adapter_test() {
        System.out.println("test adapter...");
        LogFileOperateApi logFileOperate = new LogFileOperate(null);
        LogDbOperateApi logDbOperate = new Adapter(logFileOperate);
        // 虽然是调用的日志数据库操作接口，但实际被适配后，转调文件操作接口，对调用者透明
        logDbOperate.createLog(null);
        logDbOperate.getAllLog();
    }
}
